#pragma once

class TextureUI;

class SelectionMgr : public Singleton<SelectionMgr>
{
	bool m_drawSel;
	Vertex3F m_position;
	CFont m_coordinates;
	ToolBar* m_toolBar;
	ToolBar* m_upBar;
	Panel* m_tePanel;
	float m_radius, m_intensity;
	ui32 m_type;
	ui32 m_mode;
	ui32 m_texFlags;
	char m_coordClient[255];
	i32 m_lastAreaId;
	ui32 m_mapId;
	Vertex3F m_entryPoint;
	Vertex3F m_lastMouse;
	Vertex2F m_moveMouse;
	bool m_quickMode;
	bool m_quickKey;

	LayerUI* m_layerUI;
	TerrainUI* m_terrainUI;
	TextureUI* m_texUI;
	TexSelUI* m_texSel;

	bool m_drawWMO, m_drawMDX;

	void ResetCam(UIButton<SelectionMgr>* /*pButton*/) // Will not be inlined cause referenced in m_toolBar->AddButton
	{
		sCamera.SetCameraPosition(m_entryPoint.x, m_entryPoint.y, m_entryPoint.z);
	}

	void CreateWdl(UIButton<SelectionMgr>* /*pButton*/);

	void ToggleAreaDbc(UIButton<SelectionMgr>*);

	void ToggleTerrainUI(UIButton<SelectionMgr>*)
	{
		m_terrainUI->Toggle();
	}

	void ToggleTextureUI(UIButton<SelectionMgr>*);

	void ToggleTexSelUI(UIButton<SelectionMgr>*);
	void ToggleSettings(UIButton<SelectionMgr>*);
	
public:
	SelectionMgr();

	Texture* m_selCircle;

	void ShowTextureSelection();

	bool GetDrawWMO() { return m_drawWMO; }
	bool GetDrawMDX() { return m_drawMDX; }

	Vertex3F& getLastMousePos() { return m_lastMouse; }

	void OnVirtualKey(char vKeyCode)
	{
		switch(vKeyCode)
		{
		case VK_F2:
			m_drawWMO = !m_drawWMO;
			break;
		case VK_F3:
			m_drawMDX = !m_drawMDX;
			break;
		case VK_F1:
			sHelp.Toggle();
			break;
		}
	}

	bool IsAlignEnabled() { return m_terrainUI->IsAlignEnabled(); }

	float GetTextureGradient();
	float GetTextureIntensity();

	void Resize();

	float& GetRadius() { return m_radius; }
	inline void SetRadius(float radius)
	{
		m_radius = radius;
	}
	inline float GetIntensity() { return m_intensity; }
	inline void SetIntensity(float intensity) { m_intensity = intensity; }
	inline void SetType(ui32 type) { m_type = type; }
	inline void SetMode(ui32 mode) { m_mode = mode; }
	inline ui32 GetTexFlags() { return m_texFlags; }
	inline void SetTexFlags(ui32 flags) { m_texFlags = flags; }
	void update();

	void EnableMCCV();
	void EnableTexturing();

	void SetMouseMove(ui32 x, ui32 y)
	{
		m_moveMouse.x = (float)x;
		m_moveMouse.y = (float)y;
	}

	inline ui32 GetInternalMap() { return m_mapId; }

	inline void SetEntryPoint(Vertex3F point, ui32 mapId)
	{
		m_mapId = mapId;
		m_entryPoint = point;
	}

	void SetSelectionTexture(ID3DXEffect* pEffect);
	void OnKey(char key);
	void Render();

	inline void SetClickPoint(Vertex3F position)
	{
		if(m_quickMode)
			return;
		if(!sTutorial.TutorialShown(TUTORIAL_TERRAIN_CLICK))
			sTutorial.ShowTutorial("Changing terrain", helpTerrain);
		m_position = position;
		m_drawSel = true;
		m_layerUI->CheckChunk(m_position);
	}

	void CheckKeys();

	bool& GetSelection() { return m_drawSel; }
};

#define sSelection (*SelectionMgr::GetInstance())